$(function () {
    $("#tijiao").click(function postData() {
        var formData = new FormData();
        formData.append("file", $("#uploadImage")[0].files[0]);
        formData.append("id",$("#id").val());
        $.ajax({
            url:'http://localhost:8080/fileUpload',
            type: "post",
            data: formData,
            processData: false, // 告诉jQuery不要去处理发送的数据
            contentType: false, // 告诉jQuery不要去设置Content-Type请求头
            dataType: "text",
            success: function(data) {
                var params = "../images/"+data;
                $("#img").attr("src", params);
            },
            error: function(data) {

            }
        });

    });
    $("#zongtijiao").click(function (){
        var url='/newproducttijiao';
        var form = $("<form method='post'></form>");
        form.attr({"action":url});
        var input = $("<input type='hidden'>");
        input.attr({"name":"descn"});
        var jh=document.getElementById("img").src.substring(21);
        input.val(".."+jh);
        form.append(input);
        var input2 = $("<input type='hidden'>");
        input2.attr({"name":"productid"});
        input2.val($("#id").val());
        form.append(input2);
        var input4 = $("<input type='hidden'>");
        input4.attr({"name":"category"});
        input4.val($("#category").val());
        form.append(input4);
        var input3 = $("<input type='hidden'>");
        input3.attr({"name":"name"});
        input3.val($("#name").val());
        form.append(input3);
        var input5 = $("<input type='hidden'>");
        input5.attr({"name":"miaoshu"});
        input5.val($("#miaoshu").val());
        form.append(input5);
        $("#submitForm").append(form);
        form.submit();
        $("#submitForm").html("");
    });

});